# 接口参数化
import csv

import requests


class WorkFlowNewTestV2:
    def register_test(self, url, user_info, exp_result, name):

        # 发送请求
        res = requests.post(url, data=user_info).text
        r = res.find(exp_result)
        if r > 0:
            print(name + "测试通过")
        else:
            print(name + "测试不通过")


if __name__ == '__main__':
    obj = WorkFlowNewTestV2()
    file = open("../data/interface_datas.csv", "r")
    tables = csv.reader(file)
    user_info = {}
    for row in tables:
        url = row[1]
        exp_result = row[3]
        name = row[5]
        j = int(row[6])
        for i in range(7, 2 * j + 7, 2):
            user_info[row[i]] = row[i + 1]
        obj.register_test(url, user_info, exp_result, name)
        user_info = {}
